﻿/**
* ...
* @author Default
* @version 0.1
*/

package bdz.common.utils{

	public class DateUtils {
		private static var months:Array = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
		private static var days:Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
		public static function getDayString(indx:Number, long:Boolean = true):String{
			return !long ? String(days[indx]).substring(0, 3) : days[indx];
		}
		public static function getMonthString(indx:Number, long:Boolean = true):String{
			return !long ? String(months[indx]).substring(0, 3) : months[indx];
		}
		public static function getNumberOfDays(month:Number, year:Number):Number {
			var daysinmonth:Array = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
			if (((year%4) == 0) && ((year%100) != 0) || ((year%400) == 0)) {
				if (month == 1) {
					//leap year value
					return 29;
				}
			}
			return daysinmonth[month];
		}
		public static function addWeeks(date:Date, weeks:Number):Date {
			return addDays(date, weeks*7);
		}

		public static function addDays(date:Date, days:Number):Date {
			return addHours(date, days*24);
		}

		public static function addHours(date:Date, hrs:Number):Date {
			return addMinutes(date, hrs*60);
		}

		public static function addMinutes(date:Date, mins:Number):Date {
			return addSeconds(date, mins*60);
		}

		public static function addSeconds(date:Date, secs:Number):Date {
			var mSecs:Number = secs * 1000;
			var sum:Number = mSecs + date.getTime();
			return new Date(sum);
		}

	}
	
}